package cn.xueden.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**功能描述：时间工具类
 * @author:梁志杰
 * @date:2025/6/8
 * @description:cn.xueden.util
 * @version:1.0
 */
public class DateTimeUtil {

    private static String dataFormat = "yyyy-MM-dd";
    private static String format = "yyyy-MM-dd HH:mm:ss";

    public DateTimeUtil() {
    }

    /**
     * 获取当前时间
     * @return
     */
    public static LocalDateTime getDateTime(){
        return LocalDateTime.parse(datetimeToStr(LocalDateTime.now()), DateTimeFormatter.ofPattern(format));
    }


    /**
     * 把字符串时间日期转为LocalDateTime格式
     *
     * @param dateTime 需要转换的字符串
     * @return 返回LocalDateTime格式
     */
    public static String datetimeToStr(LocalDateTime dateTime) {
        return DateTimeFormatter.ofPattern(format).format(dateTime);

    }

    /**
     * 获取当前时间
     * @return
     */
    public static LocalDate getDate() {
        return LocalDate.parse(dateToStr(LocalDate.now()), DateTimeFormatter.ofPattern(dataFormat));
    }

    /**
     * 当前时间转换为字符串
     * @param date
     * @return
     */
    public static String dateToStr(LocalDate date) {
        return DateTimeFormatter.ofPattern(dataFormat).format(date);

    }
}
